package cc.geguo;

import java.security.PrivateKey;
import java.security.PublicKey;

public class Main {

    public static final String PASSWORD = "123456";// keystore 密码
    public static final String ALIAS = "cc.geguo";
    public static final String CERTIFICATE_PATH = "geguo.cer";// 证书文件路径
    public static final String KEYSTORE_PATH = "cert.keystore";// 密钥对文件
    public static final String DATA = "Hello World";
    public static void main(String[] args) throws Exception{
       /**
        * 1. 获取私钥
        * 2. 获取公钥
        * 3. 加密
        * 4. 解密
        * */
      PrivateKey privateKey =  CertificateUtil.getPrivateKeyFromKeyStore(KEYSTORE_PATH,ALIAS,PASSWORD);
      PublicKey publicKey = CertificateUtil.getPublicKeyFromCertificate(CERTIFICATE_PATH);
      byte[] cipher = CertificateUtil.encrypt(DATA.getBytes(),publicKey);
        System.out.println(new String(cipher));
        byte[] plain = CertificateUtil.decrypt(cipher,privateKey);
        System.out.println(new String(plain));
    }
}
